<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams">
      <el-form-item label="用户姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          clearable
          placeholder="请输入用户姓名"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="cyan" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button-group>
          <el-button
            v-hasPermi="['system:electronicSignature:add']"
            icon="el-icon-plus"
            size="mini"
            type="success"
            @click="handleAdd"
          >新增
          </el-button>
        </el-button-group>
      </el-col>
      <el-col :span="1.5">
        <el-button-group>
          <el-button
            v-hasPermi="['system:electronicSignature:edit']"
            :disabled="single"
            icon="el-icon-edit"
            size="mini"
            type="primary"
            @click="handleUpdate"
          >修改
          </el-button>
          <el-button
            v-hasPermi="['system:electronicSignature:remove']"
            :disabled="single"
            icon="el-icon-delete"
            size="mini"
            type="primary"
            @click="handleDelete"
          >删除
          </el-button>
        </el-button-group>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="electronicSignatureList" height="calc(100vh - 211px)"
              highlight-current-row @current-change="handleCurrentChange">
      <el-table-column align="center" label="电子签章编号" prop="id"/>
      <el-table-column align="center" label="用户姓名" prop="userName"/>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <edit ref="editDialog" @refreshDataList="getList"></edit>
  </div>
</template>

<script>
import {
  delElectronicSignature,
  exportElectronicSignature,
  listElectronicSignature
} from '@/api/system/electronicSignature'
import Edit from './edit'

export default {
  name: 'ElectronicSignature',
  components: {Edit},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      id: '',
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 电子签章表格数据
      electronicSignatureList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null
      }
    }

  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询电子签章列表 */
    getList() {
      this.loading = true
      listElectronicSignature(this.queryParams).then(response => {
        this.electronicSignatureList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    //选中数据
    handleCurrentChange(val) {
      if (val) {
        this.id = val.id
        if (this.id) {
          this.single = false
        }
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs['editDialog'].reset()
      this.$refs['editDialog'].getUserProfile()
      this.$refs['editDialog'].open = true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs['editDialog'].reset()
      this.$refs['editDialog'].open = true
      const id = row.id || this.id
      this.$refs['editDialog'].init(id)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.id
      this.$confirm('是否确认删除电子签章编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return delElectronicSignature(ids)
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      }).catch(function () {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有电子签章数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return exportElectronicSignature(queryParams)
      }).then(response => {
        this.download(response.msg)
      }).catch(function () {
      })
    }
  }
}
</script>
